import json
import base64
import asyncio



print(f"----1111:    {int(130).to_bytes(1, 'big')}")

bbb = b'1090'
ccc = b'\x10\x20'
print(f"----2222:   {int.from_bytes(bbb,'big')}")
print(f"----2222:   {int.from_bytes(bbb,'little')}")
print(f"----6666:   {int.from_bytes(ccc,'big')}")
print(f"----6666:   {int.from_bytes(ccc,'little')}")

data = [1, 2, 3, 4]
res = int.from_bytes(data[:4], 'big')
print(f"----3333:   {res}")



print("----:" , 21 & 0x01)
print("----:" , 67 & 0x02)
print("----:" , 20 & 0x04)


list = []
list.insert(0,0)
list.insert(0,1)
print("----list:" , list)
print("----list:" , list[1])
list.pop(1)
list.insert(0,2)
print("----list:" , list)
print("----list:" , list[1])
list.pop(1)
list.insert(0,3)
print("----list:" , list)
print("----list:" , list[1])
list.pop(1)
list.insert(0,4)
print("----list:" , list)
print("----list:" , list[1])

list.pop(1)
print("----list:" , list)



# !\x00\x00\x08:
aa = int.from_bytes(b'\x08:', 'big', signed=False)
print("----aa:" , aa)



num_list = [1,2,3,4,5,6,7,8]
print("-".join(str(i) for i in num_list))


for i in range(len(num_list)-1, -1, -1):
    print(f"--------item: {num_list[i]}")



aaa = "eyIxOTY2MDkiOiBbXSwgIjE5NjYxMCI6IFtdLCAiMTk2NjExIjogW10sICIxOTY2MTIiOiBbXSwgIjEzMTA3MyI6IFtdfQ=="
msg_bytes = aaa.encode()
ori_data = base64.b64decode(msg_bytes).decode()
print(f"--------ori_data: {ori_data}")


async def test():
    queue = asyncio.Queue()
    for i in range(10):
        await queue.put(i * 2)

    print(f"--111111--queue: {queue}")
    first_element = queue._queue[queue.qsize() - 1]
    print(f"----first_element: {first_element}")
    print(f"--222222--queue: {queue}")

    first_element_1 = await queue.get()
    print(f"----first_element_1: {first_element_1}")
    print(f"--222222--queue: {queue}")

asyncio.run(test())



for i in range(10):
    for m in range(20):
        if m == 9:
            print(f"-----m: {m}")
            break
    print(f"-----i: {i}")

aa = ["aaa","bbb","ccc","ddd","eee"]
bb = [index for index,item in enumerate(aa) if item == "ccc"]
print(f"-----bb: {bb}----")


device_id = int("00020001" ,16)
print(f"-----------device_id: {device_id}")

aa = 131073
bb = "%08x" % aa
print(f"-----------device_id: {bb}")


def test_func():
    cmd = 2002
    data = 1000
    return cmd, data

AAA = test_func()
print(f"-----------AAA: {AAA[0]}, {AAA[1]}")


from flaw_point import FlawPoint
from flow_point_encoder import FlowPointEncoder
import json
point_matrix = [[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]]
flaw_point_1 = FlawPoint(flaw_id=1, point_matrix=point_matrix)
flaw_point_2 = FlawPoint(flaw_id=2, point_matrix=point_matrix)
flaw_point_3 = FlawPoint(flaw_id=3, point_matrix=point_matrix)
flaw_point_4 = FlawPoint(flaw_id=4, point_matrix=point_matrix)
flaw_point_list = [flaw_point_1, flaw_point_2,flaw_point_3,flaw_point_4]

ai_res = dict(device_id="00020001", flaws=flaw_point_list)

flaw_point_str = json.dumps(ai_res, cls=FlowPointEncoder)
print(f"-----------flaw_point_str: {flaw_point_str}")



aa = [0,1,2,3,4,5]
print(f"------{aa[2]}")


def test(item):
    tmp = str(item).split("-")
    errorPosition_key = tmp[0]
    device_id = errorPosition_key.split("_")[0]
    area_id = errorPosition_key.split("_")[1]
    errorPositionId = tmp[1]

    print(f"device_id:{device_id} ,area_id:{area_id},  errorPositionId:{errorPositionId}")

test("34_3-")



line_status = {
    "1":"1",
    "2":"2",
    "3":"3",
    "5":"4"
}
component_ids = [1,3,6]
line_status = {component_id: line_status.get(str(component_id), 0) for component_id in component_ids}
print(f"------line_status: {line_status}")


